<template>
    <div>
        <van-nav-bar right-text="注册" left-arrow @click-left="onClickLeft" @click-right="onClickRight" />

        <div class="content">
            <h1>手机快捷登录</h1>
            <p>未注册的手机号将自动创建账号</p>
        </div>

        <div class="login">
            <van-form @submit="onSubmit">
                <van-cell-group inset>
                    <van-field v-model="username" name="mobile" label="账号" placeholder="请输入账号" autocomplete="username"
                        style="border-bottom: 0.1px solid #EBEBED;" />
                    <van-field v-model="password" type="password" name="password" label="密码" placeholder="请输入密码"
                        autocomplete="current-password" style="border-bottom: 0.1px solid #EBEBED;" />
                </van-cell-group>

                <van-checkbox icon-size="16px" checked-color="#0FAB6B"
                    style="margin-top: 20px;padding-left: 10px;font-size: 13px;" v-model="checked">
                    我已阅读并同意 <a style="color:#0FAB6B ;">《强盛在线用户服务协议》</a>以及 <a style="color:#0FAB6B ;">《隐私政策》</a>
                </van-checkbox>

                <van-button type="primary" block native-type="submit"
                    style="background-color: rgb(15,171,107);width:90%;margin: auto;margin-top:25px;">立即登录</van-button>
            </van-form>
            <div class="select-login">
                <span @click="gophoneLogin">手机验证登录</span>

                <span>忘记密码?</span>
            </div>
        </div>
    </div>
</template>

<script setup>
import { showToast } from 'vant';
import { ref } from 'vue';
import AxiosServer from '@/router/axios';
import { useRouter } from 'vue-router';
const router = useRouter();
const onClickLeft = () => history.back();
const onClickRight = () => router.push( '/register' );

const username = ref( '' );
const password = ref( '' );
const onSubmit = async( values ) => {
    if( !checked.value ) {
        showToast( '请勾选协议' )
        return
    } else {
        const { data } = await AxiosServer.get('/ljsApi/passwordlogin', {
            params: {
                mobile: values.mobile,
                password: values.password
            }    
        } )
        console.log(data);
        if ( data.status == 200) {
            showToast(data.msg)
            router.push( '/home' )
        } else {
            showToast(data.msg)
        }
    }
    console.log( 'submit', values );
};


const checked = ref( false );
const gophoneLogin = () => {
    router.push( '/login' )
}
</script>

<style lang="scss" scoped>
.content {
    margin-left: 10px;

    h1 {
        font-size: 25px;

    }

    p {
        font-size: 12px;
        color: #8b8888;
        margin: -15px 0;
    }
}

.login {
    margin-top: 50px;
}

.select-login {
    display: flex;
    color: #8b8888;
    font-size: 13px;
    justify-content: space-between;
    margin-top: 20px;
    padding: 0 10px;
}
</style>